﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using TomShane.Neoforce.Controls;
using TomShane.Neoforce.Importers;

namespace TestMenu.Screens
{
	public class OptionsWindow : IGameScreen
	{
		Window wndOptions;
		RadioButton radDefaultSkin;
		RadioButton radGreenSkin;
		Button btnApplyChanges;
		Button btnBack;
		Manager manager;

		public TestMenu MainGame { get; set; }

		public OptionsWindow(TestMenu mainGame)
		{
			manager = TestMenu.Manager;
			MainGame = mainGame;
		}

		public void Initialize(GraphicsDeviceManager graphics, ContentManager content)
		{
			wndOptions = new Window(manager);
			wndOptions.Init();
			wndOptions.Width = graphics.PreferredBackBufferWidth;
			wndOptions.Height = graphics.PreferredBackBufferHeight;
			wndOptions.Center();
			wndOptions.Movable = false;
			wndOptions.Resizable = false;
			wndOptions.Text = "Optionen";
			wndOptions.Visible = false;

			radDefaultSkin = new RadioButton(manager);
			radDefaultSkin.Init();
			radDefaultSkin.Parent = wndOptions;
			radDefaultSkin.Text = "Red Skin";
			radDefaultSkin.Left = wndOptions.ClientWidth / 8;
			radDefaultSkin.Top = wndOptions.ClientHeight / 8;
			radDefaultSkin.Width = wndOptions.ClientWidth / 4;
			radDefaultSkin.Height = wndOptions.ClientHeight / 16;

			radGreenSkin = new RadioButton(manager);
			radGreenSkin.Init();
			radGreenSkin.Parent = wndOptions;
			radGreenSkin.Text = "Green Skin";
			radGreenSkin.Left = wndOptions.ClientWidth / 8;
			radGreenSkin.Top = wndOptions.ClientHeight / 8 * 2;
			radGreenSkin.Width = wndOptions.ClientWidth / 4;
			radGreenSkin.Height = wndOptions.ClientHeight / 16;

			btnApplyChanges = new Button(manager);
			btnApplyChanges.Init();
			btnApplyChanges.Parent = wndOptions;
			btnApplyChanges.Text = "Anwenden";
			btnApplyChanges.Left = wndOptions.ClientWidth / 2;
			btnApplyChanges.Top = wndOptions.ClientHeight / 16 * 3;
			btnApplyChanges.Width = wndOptions.ClientWidth / 4;
			btnApplyChanges.Height = wndOptions.ClientHeight / 16;
			btnApplyChanges.Click += new MouseEventHandler(btnApplyChanges_Click);

			btnBack = new Button(manager);
			btnBack.Init();
			btnBack.Parent = wndOptions;
			btnBack.Text = "Zurück";
			btnBack.Width = wndOptions.ClientWidth / 4;
			btnBack.Height = wndOptions.ClientHeight / 16;
			btnBack.Left = (wndOptions.ClientWidth / 2) - (btnBack.Width / 2);
			btnBack.Top = wndOptions.ClientHeight / 8 * 7;
			btnBack.Click += new MouseEventHandler(btnBack_Click);
		}

		void btnApplyChanges_Click(object sender, MouseEventArgs e)
		{
			if (radDefaultSkin.Checked)
				manager.Skin = new Skin(manager, "Default");
			else if (!radGreenSkin.Checked)
				manager.Skin = new Skin(manager, "Green");
		}

		void btnBack_Click(object sender, MouseEventArgs e)
		{
			MainGame.SwitchGameScreen(MainGame.MainWindow);
		}

		public void UnloadContent()
		{
			wndOptions.Dispose();
			wndOptions = null;
		}

		public void Update(GameTime gameTime)
		{
			manager.Update(gameTime);
		}

		public void Draw(SpriteBatch spriteBatch, GameTime gameTime)
		{
			manager.Draw(gameTime);
		}

	}
}
